<template>
  <div>
    <h1>Post List</h1>
    <ul>
      <li v-for="post in posts" :key="post.id">{{ post.title }}</li>
    </ul>
  </div>
</template>

<script>
import {mapState,mapActions} from 'vuex'
export default {
  name:'PostList',
  metaInfo:{
    title:'Posts'
  },
  data(){
    return {
    }
  },
  computed:{
    ...mapState(['posts']),
  },
  methods:{
    ...mapActions(['getPosts'])
  },
  //Vue SSR 特殊为服务端渲染提供的一个生命周期函数
  serverPrefetch(){
    console.log("serverPrefetch")
    //发起action 返回Promise
    return this.getPosts()
  }
}
</script>

<style>

</style>